/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - Thread3
 * <p>Powered by webrx On 2021-08-24 08:53:12
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Thread3 {
    public static void main(String[] args) {
        //10秒后输出一句话
        var t = new Thread(() -> {
            try {
                TimeUnit.HOURS.sleep(1);
                System.out.println("hello world");
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        t.start();

        //指定时间输出一句  2021-08-24 09:01:30
        var t2 = new Thread(() -> {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date d = null;
            try {
                d = sdf.parse("2021-08-24 09:03:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            long end = d.getTime();
            try {
                while (true) {
                    long now = System.currentTimeMillis();
                    if (now >= end) {
                        System.out.println("时间到");
                        //调用关机程序 shutdown /s /t
                        //shutdown /a 取消关机进程
                        //Runtime run = Runtime.getRuntime();
                        //run.exec("cmd /k shutdown /s /t 0");
                        break;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        t2.start();
    }
}
